(function(app){
	app
		.controller("presentdeliverOperateCtrl",["$scope","myFactory",'$http','$state','$stateParams','$location','$ionicHistory','$timeout','$ionicLoading','$rootScope','$interval',function($scope,myFactory,$http,$state,$stateParams,$location,$ionicHistory,$timeout,$ionicLoading,$rootScope,$interval){
			//参数接收、定义
			var returnData = $stateParams.returnData; //经由查询页面点击回复后，经过后台查询后得到的数据
			var chdrnum = returnData.baseInfo.chdrnum;//保单号
			var chdrcoy = returnData.baseInfo.chdrcoy;//公司号
			var surname = returnData.baseInfo.cownm;//投保人
			var temp_sign_mid = returnData.temp_sign_mid;//投保人
			var valnum_temp="000000"; //验证码缓存
			var timeOutSign="N";//超时标志
			//参数绑定、设定
			$scope.telNo = returnData.telNo;
			$scope.baseInfo = returnData.baseInfo;//保单基本信息
			$scope.groupMap = returnData.groupMap;//照会信息分组列表，其中每个组可分别为一般照会组，补充告知组等
			var token=sessionStorage.getItem("token");
			$scope.canret = "N"; //是否需要回复标志，当为Y时表明需要回复，否则禁用或者隐藏回复组件
			$scope.canSg = "N";//是否需要签名标志，当为Y时表明需要签名，否则禁用或者隐藏签名组件
			$scope.data = {
					checkFlag: false,
					timeCon: '获取手机验证码',
					textFlag: true,
					timeReply: null,
			};
/*******************************************初始化函数begin************************************************************/
			var groupMap = returnData.groupMap;
			var group = "";
			for(var name in groupMap){//注意groupMap是一个数组集合，用该方式name得到的是每一个数组名字
				group = groupMap[name];//根据每个名字得到每个数组
				if(group[0].canshow=='Y'){//同一数组中的每条照会信息有一些公共属性，比如canshow，如果是需要在界面显示的照会，则往下执行，否则跳过
					if(group[0].canret=="Y"){
						$scope.canret = "Y";//同组有一些共同属性，所以只需要读第0个，不管哪个分组，只要有需要回复照会的，则标志更新 
						$scope.canretFlag = true;
					}else{
						$scope.canretFlag = false;
						//$scope.canretFlag = true;//临时改动
					}
					if(group[0].canSg=="Y"){
						$scope.canSg = "Y";//同上
						$scope.canSgFlag = true;
					}else{//如果不需要签名，则把整个区域点击事件取消
						$scope.canSgFlag = false;
						//$scope.canSgFlag = true;//拍照功能调试中，先默认不管什么情况都能拍照
					}	
				}
			}
/*******************************************初始化函数end************************************************************/		
			//常用回复
			$scope.isLabel = function($event,type){
				/*S2022041822029--PIC_双被保险人增额终身寿险产品系统需求 add by huanghk 20220816 start*/
				var token=sessionStorage.getItem("token");
				var timestamp=myFactory.getTimetamp();
				var sfis= "chdrnum-token-timestamp";
				var signStr="chdrnum="+chdrnum+"&token="+token+"&timestamp="+timestamp;//encodeURI(tbrName)
				var sign = myFactory.hex(signStr);
				myFactory.loadingShow();
				$http({
					method: 'GET',
					url: app.domain + 'query/checkLife2.action',
					params: {'chdrnum': chdrnum,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						if(response.data.data){
							myFactory.alert("","暂不支持双被保险人保单操作，请重新确认！","info");
						}else{
							var text = $($event.target).text();
							//alert(text);
							$("#retMsg").val(text);
							$($event.target).addClass('active').siblings('.label').removeClass('active');
							if(type=="1"){//同意
								$("#retTyp").val("1");
							}else if(type=="0"){//不同意
								$("#retTyp").val("0");
								
							}
						}
					}
					myFactory.loadingHide();
				}, function errorCallback(response) {
					myFactory.alert("","查询数据失败!","info");
					myFactory.loadingHide();
				});
				/*S2022041822029--PIC_双被保险人增额终身寿险产品系统需求 add by huanghk 20220816 end*/
			}
			var maxTime = 600;//3*60;//倒计时时间
			var timer;
			//PC端测试数据
			var testVal="R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7";

			//拍照控制
			var curentId="";
			var curentTypeName="";

			$scope.otherPtData=[];//其他资料留影，用于前端绑定，设置成一个数组
			var otherPtData=[];//其他资料留影，设置成一个数组
			var otherPtAddId=0;
			
			//签名、留影函数
			$scope.showPopupDialog = function(context_id){
				console.log('调用信易通内核签名.......');
				if(context_id=='20'){
					var data = {
						title : '投保人(签名)',
						titleSpanFromOffset : '4',
						titleSpanToOffset : '5',
						singleWidth : '150',
						singleHeight : '75',
						businessType : '1',//1:投保人签名 2：被保人签名 0:风险提示语
						Identitycardnbr : $("#cownnumOnReply").val().trim(),
						username : $("#cownmOnReply").val().trim(),
						nessesary : 'false',
						//template_serial : $("#chdrnumOnReply").val()+"_01",
						template_serial : temp_sign_mid,
						serverConfigRule : '1122'
					};
					
					/****************测试数据begin*****************/
					var appVersionFlag = myFactory.getBrowserType();
					console.log("appVersionFlag:"+appVersionFlag);
					if(appVersionFlag=="Android"){
					}else if(appVersionFlag=="IOS"){
					}else if(appVersionFlag=="Browser"){
						var testVal="R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7";
						$("#img_policyHolderSg").attr('src','data:image/gif;base64,'+testVal);
						$("#holderSgData").val(testVal);
						$("#encodedDataOnReply").val("base64");//测试数据
						$("#img_policyHolderSg").css('display','inline');
						$("#photo_cover_20").css('display','none');
						$("#text_cover_20").css('display','none');
						$("#delImg_20").css('display','inline');
						return false;
					}else{
					}
					/****************测试数据end*****************/ 	
					if(curentId!=""){
						curentId="";
					}
					curentId=context_id;
					cordova.sino.digitalSignature(callbackFunctionSign, data);//引用新的js脚本文件
				}

				if(context_id=='21'){
					var data = {
						title : '被保险人(签名)',
						titleSpanFromOffset : '5',
						titleSpanToOffset : '6',
						singleWidth : '150',
						singleHeight : '75',
						businessType : '2',//1:投保人签名 2：被保人签名 0:风险提示语
						Identitycardnbr : $("#lifenumOnReply").val(),
						username : $("#lifenmOnReply").val(),
						nessesary : 'false',
						//template_serial : $("#chdrnumOnReply").val()+"_02",
						template_serial : temp_sign_mid,
						serverConfigRule : '1124'
					};
					var appVersionFlag = myFactory.getBrowserType();
					console.log("appVersionFlag:"+appVersionFlag);
					if(appVersionFlag=="Android"){
					}else if(appVersionFlag=="IOS"){
					}else if(appVersionFlag=="Browser"){
						var testVal="R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7";
						$("#img_insuredSg").attr('src','data:image/gif;base64,'+testVal);
						$("#insuredSgData").val(testVal);
						$("#encodedDataOnReplyInsured").val("base64");//测试数据

						$("#img_insuredSg").css('display','inline');
						$("#photo_cover_21").css('display','none');
						$("#text_cover_21").css('display','none');
						$("#delImg_21").css('display','inline');
						return false;
					}else{
					}
					/****************测试数据*****************/

					if(curentId!=""){
						curentId="";
					}
					curentId=context_id;
					cordova.sino.digitalSignature(callbackFunctionSign, data);
				}
				
				if(context_id=='507'){ //附加其他资料
					//其他资料
					if(otherPtData.length==10){//其他资料（最多10张）
						myFactory.alert('','其他资料最多10张！','info');
						return false;
					}
					/****************测试数据*****************/
					var appVersionFlag = myFactory.getBrowserType();
					console.log("appVersionFlag:"+appVersionFlag);
					
					if(appVersionFlag=="Android"){
					}else if(appVersionFlag=="IOS"){
					}else if(appVersionFlag=="Browser"){//PC端测试无条件通过
						console.log("当前otherPtData.length:"+otherPtData.length);
						if(otherPtData.length==0){//重置动态资源变量
							otherPtAddId=0;
						}
						var otherPtDataJson = JSON.stringify(otherPtData);
						console.log("当前otherPtData:"+otherPtDataJson);

						//数组参数
						var testVal="R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7";
						var keyId=otherPtAddId;
						var url='data:image/gif;base64,'+testVal;
						var ido=otherPtAddId;
						var idPt=testVal;
						var picVal={'keyId':keyId,'url': url,'ido':ido,'idPt':idPt};

						otherPtData.push(picVal);
						otherPtAddId++;
						$scope.otherPtData=otherPtData;

						console.log("---------------------add begin-----------------------");
						console.log("点击新增后otherPtData.length:"+otherPtData.length);
						var otherPtDataJson = JSON.stringify(otherPtData);
						console.log("点击新增后otherPtData:"+otherPtDataJson);

						var otherPtDataTemp=$scope.otherPtData;
						console.log("点击新增后otherPtDataTemp.length:"+otherPtDataTemp.length);
						var otherPtDataTempJson = JSON.stringify(otherPtDataTemp);
						console.log("点击新增后otherPtDataTemp:"+otherPtDataTempJson);
						console.log("---------------------add end-----------------------");

						return false;
					}else{
						//什么都不做 进入下一步
					}
					
					/*var photoData = {};
					if(appVersionFlag=="Android" || appVersionFlag=="Browser"){//安卓版本未有解决新接口，需分离平台调用
						photoData = {
								//title : '投保人（留影）',
								width : '960',
								height : '720',
								mono : 'true',//bool 此选项无效
								//quality : '50',//int 0~100 推荐85
								quality : '85',
								openFromGallery : 'false',//是否从相册选择照片
								//openFromGallery : 'true',//是否从相册选择照片
								//businessType : '2'
								businessType : '0'//去除“请拍摄人脸”
						};
					}else if(appVersionFlag=="IOS"){
						var openFromGallery=false; //true:从相册中选择，false:拍照
						data = {
								openFromGallery : openFromGallery,//是否从相册选择照片：true:从相册中选择，false:拍照
								imgType : 'OtherPhoto'//固定值，千万不要改动
						};
					}*/
					var openFromGallery=false; //true:从相册中选择，false:拍照
					var photoData = {
							openFromGallery : openFromGallery,//是否从相册选择照片：true:从相册中选择，false:拍照
							imgType : 'OtherPhoto'//固定值，千万不要改动
					};
					
					if(curentId!=""){
						curentId="";
					}
					curentId=context_id;
					//cordova.sino.takePhoto(callbackFunctionSign, photoData);
					/*if(appVersionFlag=="Android"){//安卓版本未有解决新接口，需分离平台调用
						cordova.sino.takePhoto(callbackFunctionPhoto, photoData);//北京CA拍照接口
					}else if(appVersionFlag=="IOS"){
						cordova.sino.takePhotoOther(callbackFunctionPhoto, photoData);//信易通拍照接口
					}*/
					cordova.sino.takePhotoOther(callbackFunctionPhoto, photoData);//信易通拍照接口
				}
			}

			//签名回调函数、其他资料回调函数（参数可以复用）
			var callbackFunctionSign = function(result){
				var data = result.data;
				var val = data.signImg;//签名数据
				var signdata= data.signatureData;//加密数据
				if(curentId!=''){
					if(curentId=='20'){
						$("#img_policyHolderSg").css('display','inline');
						$("#photo_cover_20").css('display','none');
						$("#text_cover_20").css('display','none');
						//$("#img_policyHolderSg").src="data:image/png;base64," + val;//这么设置不起作用
						$("#img_policyHolderSg").attr('src','data:image/gif;base64,'+val);
						$("#holderSgData").val(val);
						$("#encodedDataOnReply").val(signdata);
						$("#delImg_20").css('display','inline');
						curentId='';
					}
					if(curentId=='21'){
						$("#img_insuredSg").css('display','inline');
						$("#photo_cover_21").css('display','none');
						$("#text_cover_21").css('display','none');
						$("#img_insuredSg").attr('src','data:image/gif;base64,'+val);//data:image/gif;base64,{{policyHolderSg}}
						$("#insuredSgData").val(val);
						//$("#encodedDataOnReply").val(signdata);
						$("#encodedDataOnReplyInsured").val(signdata);
						$("#delImg_21").css('display','inline');
						curentId='';
					}
					if(curentId=='507'){
						//console.log("当前otherPtData.length:"+otherPtData.length);
						//myFactory.alert('','当前otherPtData.length:'+otherPtData.length,'info');
						if(otherPtData.length==0){//重置动态资源变量
							otherPtAddId=0;
						}
						var otherPtDataJson = JSON.stringify(otherPtData);
						//console.log("当前otherPtData:"+otherPtDataJson);

						//数组参数
						var keyId=otherPtAddId;
						var url='data:image/gif;base64,'+val;
						var ido=otherPtAddId;
						var idPt=val;

						var picVal={'keyId':keyId,'url': url,'ido':ido,'idPt':idPt};
						otherPtData.push(picVal);
						otherPtAddId++;
						//$scope.otherPtData=otherPtData;
						$scope.$apply(function () {
							$scope.otherPtData=otherPtData;
						});

						/*console.log("---------------------add begin-----------------------");
						console.log("点击新增后otherPtData.length:"+otherPtData.length);
						var otherPtDataJson = JSON.stringify(otherPtData);
						console.log("点击新增后otherPtData:"+otherPtDataJson);

						var otherPtDataTemp=$scope.otherPtData;
						console.log("点击新增后otherPtDataTemp.length:"+otherPtDataTemp.length);
						var otherPtDataTempJson = JSON.stringify(otherPtDataTemp);
						console.log("点击新增后otherPtDataTemp:"+otherPtDataTempJson);
						console.log("---------------------add end-----------------------");*/
						curentId='';
						
					}
				}
				
			}
			var callbackFunctionPhoto = function(result){
				var data = result.data;
				/*var val = "";
				var appVersionFlag = myFactory.getBrowserType();
				console.log("appVersionFlag:"+appVersionFlag);
				if(appVersionFlag=="Android"){//安卓版本未有解决新接口，需分离平台调用
					val = data.signImg;//拍照数据
				}else if(appVersionFlag=="IOS"){
					val = data.Base64Img;//拍照数据
				}*/
				var val = data.Base64Img;//拍照数据
				if(val==undefined || val==null || val==""){
					return false;
				}
				if(curentId!=''){
					if(curentId=='507'){
						if(otherPtData.length==0){//重置动态资源变量
							otherPtAddId=0;
						}
						var otherPtDataJson = JSON.stringify(otherPtData);
						
						//数组参数
						var keyId=otherPtAddId;
						var url='data:image/gif;base64,'+val;
						var ido=otherPtAddId;
						var idPt=val;
						
						var picVal={'keyId':keyId,'url': url,'ido':ido,'idPt':idPt};
						otherPtData.push(picVal);
						otherPtAddId++;
						//$scope.otherPtData=otherPtData;
						$scope.$apply(function () {
							$scope.otherPtData=otherPtData;
						});
						curentId='';
					}
				}
				
			}
			
			//点击删除签名图片
			$scope.deleteSign = function(e,context_id){
				e.stopPropagation();
				if(context_id=='20'){
					//$scope.img_policyHolderSgFlag=false;
					$("#img_policyHolderSg").css('display','none');
					$("#img_policyHolderSg").attr('src','');
					$("#holderSgData").val("");
					$("#encodedDataOnReply").val("");
				}

				if(context_id=='21'){
					$("#img_insuredSg").css('display','none');
					$("#img_insuredSg").attr('src','');
					$("#insuredSgData").val("");
					$("#encodedDataOnReplyInsured").val("");
				}

				$("#photo_cover_"+context_id).css('display','block');
				$("#text_cover_"+context_id).css('display','block');
				$("#delImg_"+context_id).css('display','none');
			}

			//点击删除签名图片deletePhoto_otherPt
			$scope.deletePhoto_otherPt = function($event,context_id,keyId){
				//e.stopPropagation();
				if(context_id=='507'){
					$($event).parent('.create_img_wrap').remove();

					console.log("删除keyId:"+keyId);
					for(var i=0;i<otherPtData.length;i++) {
						var keyIdTemp = otherPtData[i].keyId;
						if(keyIdTemp==keyId) {
							otherPtData.splice(i,1);
						}
					}

					console.log("--------------------del begin------------------------");
					//console.log("点击删除后tmpData.length:"+otherPtData.length);
					var otherPtDataJson = JSON.stringify(otherPtData);
					//console.log("剩余数据otherPtData:"+otherPtDataJson);

					var otherPtDataTemp=$scope.otherPtData;
					//console.log("点击删除后otherPtDataTemp.length:"+otherPtDataTemp.length);
					var otherPtDataTempJson = JSON.stringify(otherPtDataTemp);
					//console.log("点击删除后otherPtDataTempJson:"+otherPtDataTempJson);
					console.log("--------------------del end------------------------");
				}

			}
			
			//移动保全应用系统安全开发检查表 add by huanghk 20230802 start
			//var initCode=getInitCode();
			//$scope.code=initCode;
			getInitCode();
			//移动保全应用系统安全开发检查表 add by huanghk 20230802 end
			//图片验证码
			function getInitCode(){
				//移动保全应用系统安全开发检查表 add by huanghk 20230802 start
				/*var code = "";
				var codeLength = 4; //验证码的长度
				var codeChars = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
					'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
					'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); //所有候选组成验证码的字符，当然也可以用中文的
				for (var i = 0; i < codeLength; i++)
				{
					var charNum = Math.floor(Math.random() * 52);
					code += codeChars[charNum];
				}
				valnum_temp=code;
				return code;*/
				var checkCode = document.getElementById("checkCode");
                var timestamp=myFactory.getTimetamp();
				var sfis= "token-timestamp";
				var signStr="token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				$http({
					method: 'post',
					url: app.domain + "common/captchaImage.action",
					data:{'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						$scope.uuid = response.data.data.uuid;
						//code = response.data.data.code;
						var img = response.data.data.img;
						if (checkCode){
							//checkCode.className = "code";
							//checkCode.innerHTML = code;
							//$scope.code= code;
							checkCode.src="data:image/jpg;base64,"+img;
						}
						console.log(code);
					}else{
						myFactory.alert('','获取图片验证码失败！','info');
					}
				}, function errorCallback(response) {
					myFactory.alert('','获取图片验证码失败！','info');
				});
				//移动保全应用系统安全开发检查表 add by huanghk 20230802 end
			}

			$scope.changeImg = function(id) {
				var code = "";
				var codeLength = 4; //验证码的长度
				var checkCode = document.getElementById("checkCode");
				/*var codeChars = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
					'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
					'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); //所有候选组成验证码的字符，当然也可以用中文的
				for (var i = 0; i < codeLength; i++)
				{
					var charNum = Math.floor(Math.random() * 52);
					code += codeChars[charNum];
				}
				code=getInitCode();
				if (checkCode)
				{
					checkCode.className = "code";
					checkCode.innerHTML = code;
				}*/
				getInitCode();
				//开发测试直接赋值
				//console.log(code);
				//$("#valnum").val(code);

			}

			//图片验证码校验
			$scope.validateCode = function(){
				var flag=false;
				//var inputCode = document.getElementById("inputCode").value;
				var valnum = $("#valnum").val();
				if (valnum.length <= 0){
					//$.toast("请输入验证码！","text");
					myFactory.alert('','请输入图片验证码！','info');
					$("#valnum").focus();
					return flag;
				} else if (valnum.length < 4) {
					//$("#lbtime").html("输入图片验证码有误，请重新输入！");
					myFactory.alert('','输入图片验证码有误，请重新输入！','info');
					//$scope.changeImg('valnumPic');
					$("#valnum").focus();
					return flag;
				//移动保全应用系统安全开发检查表 add by huanghk 20230802 start
				/*} else if (valnum_temp.toUpperCase() != valnum.toUpperCase()){
					//$.toast("验证码输入有误！","text");
					myFactory.alert('','输入图片验证码有误，请重新输入！','info');
					//$scope.changeImg('valnumPic');
					$("#valnum").focus();
					return flag;*/
				//移动保全应用系统安全开发检查表 add by huanghk 20230802 end
				} else {
					//$.toast("验证码正确！","text");
					//myFactory.alert('','验证码正确！','info');
					flag=true;
				}
				return flag;
			}
			
			
			$scope.otherPhoto = function(){
				$("#other_photo").fadeToggle(50);

				$("#other_photo .myDialog_content .btn_close").click(function(){
					$(this).parents('#other_photo').fadeOut(50);
				});
				
				$("#myDialog .myDialog_black").click(function(){
					$(this).parent('#other_photo').fadeOut(50);
				});
			}
			
			//点击获取验证码触发函数
			$scope.getValidateNum = function(){
			//function getValidateNum(){
				var telNo = $("#telNo").val().trim();
				if(!telNo){
					myFactory.alert('','手机号码为空！请先办理通讯方式变更','info');
					return;
				}

				var validateCode=$scope.validateCode();
				if(!validateCode){
					return false;
				}
				//移动保全应用系统安全开发检查表 add by huanghk 20230802 start
				var valnum = $("#valnum").val();	
				var uuid = $scope.uuid;
				var url ="common/getValidateNumForMpnd.action";
				myFactory.loadingShow();//显示加载圈
				var timestamp=myFactory.getTimetamp();
				//var sfis= "telNo-surname-policyNo-token-timestamp";
				//var signStr="telNo="+telNo+"&surname="+encodeURI(surname)+"&policyNo="+chdrnum+"&token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sfis= "telNo-policyNo-valfrom-valnum-token-timestamp";
				var signStr="telNo="+telNo+"&policyNo="+chdrnum+"&valfrom="+uuid+"&valnum="+valnum+"&token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				$http({
					method: 'GET',
					url: app.domain + url,
					params: {"telNo":telNo, "surname":surname, "policyNo":chdrnum,"valfrom":uuid,"valnum":valnum,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						//$("#lbtime").val("");
						var sendStatus = response.data.data.sendStatus;
						var codeTemp = response.data.data.code;
						console.log("return phone code:"+codeTemp);
						myFactory.loadingHide();
						if(codeTemp=='000000'){
							myFactory.alert('','输入图片验证码有误，请重新输入！','info');
						}else{
							$scope.startReplyIterval();
							//text = eval(text);
							//$("#sbefore").hide();
							//$("#safter").show();
							//$("#send").addClass('ui-disabled');//屏蔽“获取验证码”按钮
							$("#vlData").val(codeTemp);
							/*$.confirm("测试：是否自动填入手机验证码", "", function() {
								$("#code").val(codeTemp);//测试，确认是否自动填入手机验证码
							});*/
							if(sendStatus=='-2'){
								myFactory.alert('','获取手机验证码发送异常！','info');
							}
							if(sendStatus=='3'){
								myFactory.alert('','获取手机验证码太频繁,请稍候再试！','info');
							}
							if(sendStatus=='10'){
								myFactory.alert('','获取手机验证码超过每小时限制次数,请稍后重试！','info');
							}
						}
					}
				}, function errorCallback(response) {
					myFactory.alert('','请求手机验证码失败，请稍后重试！','info');
					myFactory.loadingHide();
				});
				//移动保全应用系统安全开发检查表 add by huanghk 20230802 end
			}
			//手机验证码倒计时180秒
			$scope.startReplyIterval = function(){
				maxTime=180;//10;//180
				timeOutSign="N";
				$scope.data.textFlag = false;
				$scope.data.timeCon = "有效期："+maxTime+"S";
				$scope.data.timeReply = $interval(function(){
					//console.log("rest time1:"+maxTime);
					$("#ipttime").val(maxTime);
					maxTime--;
					//console.log("rest time2:"+maxTime);

					if (maxTime < 1) {
						$scope.data.timeCon = "获取手机验证码";
						$scope.data.textFlag = true;
						$interval.cancel($scope.data.timeReply);
					} else {
						$scope.data.timeCon = "有效期："+maxTime+"S";
					}

					if(maxTime==0){
						//myFactory.alert('','手机验证码已过期！请重新获取验证码','info');
						//jQuery("#send").removeClass('ui-disabled');
						
						//$scope.changeImg('valnumPic');//优化一下，过期不刷新，免得客户觉得又要多一次输入验证码
						//$("#valnum").val("");
						//stopIterval(timer);
						timeOutSign="Y";
						$("#ipttime").val(maxTime);
						return false;
					}
		        }, 1000);
			}
			
			//提交
			$scope.gotoSubmit = function(){
				myFactory.loadingShow();//显示加载圈
				//校验部分
				var policyHolderSg = $("#holderSgData").val();
		 		var insuredSg = $("#insuredSgData").val()==undefined ? "":$("#insuredSgData").val();
		 		
		 		var retMsg = $("#retMsg").val();
		 		var retTyp = $("#retTyp").val();
		 		var limitTime = $("#ipttime").val();
		 		
		 		if($scope.canSgFlag == true){ //如果不需要签名，则也不需要获取短信，以及不需要验证  BY ZZQ 2018-2-28   追加：也不需要图片验证 BY ZZQ 2018-3-5
			 		var validateCode=$scope.validateCode();
					if(!validateCode){
						myFactory.loadingHide();
						return false;
					}
				
					if(!$("#code").val()){
						myFactory.alert('','请输入手机验证码!','info');
						myFactory.loadingHide();
						return false;
					}
					if(parseInt(limitTime)<=0 || timeOutSign=="Y"){
						myFactory.alert('','手机验证码已经过期!请重新获取验证码!','info');
						myFactory.loadingHide();
						return false;
					}
					var codeSign=myFactory.hex($("#code").val());
					if(codeSign!=$("#vlData").val()){
						myFactory.alert('','手机验证码输入错误!','info');
						myFactory.loadingHide();
						return false;
					}
					if(maxTime==0){
						myFactory.alert('','手机验证码已过期！请重新获取验证码','info');
						myFactory.loadingHide();
						return false;
					}
				}
				
				if($scope.canretFlag){ //如果回复标志是true，则需要对回复字段进行校验
					if(retTyp.trim()==""){
						myFactory.alert('','请选择回复状态','info');
						myFactory.loadingHide();
		 				return false
		 			}
					if(retMsg.trim()==""){
						myFactory.alert('','照会回复内容不能为空!','info');
						myFactory.loadingHide();
		 				return false
		 			}
				}
				if($scope.canSgFlag){
					if(policyHolderSg.trim()==""){
						//alert("投保人签名不能为空！");
						myFactory.alert('','投保人签名不能为空!','info');
						myFactory.loadingHide();
						return false
					 }
				}
				var cownnum = $("#cownnumOnReply").val().trim();
				var lifenum = $("#lifenumOnReply").val().trim();
				var lifeAdult = $scope.baseInfo.lifeAdult.trim();
				
		 		if (cownnum==lifenum || lifeAdult!='Y'){
		 			//投被保人为同一人或 为未成年
		 		}else{
		 			if($scope.canSgFlag && cownnum!==lifenum){
		 				 if(insuredSg.trim()==""){
		 					//alert("被保人签名不能为空！");
		 					 //	$("#pop").popup("open");
		 					//$("#tishi").html("被保人签名不能为空！");
		 					myFactory.alert('','被保险人签名不能为空!','info');
		 					myFactory.loadingHide();
		 					return false
		 				 }
		 			}
		 		}
				
		 		/**********************************************计时器结束处理begin**********************************************/
		 		//提交后台之前，首先停止倒计时，并且还原成可以重新获取验证码状态
		 		$scope.data.timeCon = "获取手机验证码";
				$scope.data.textFlag = true;
				$interval.cancel($scope.data.timeReply);//立即终止倒计时,避免出现滚动条转动的时候已经到时间临界点
				timeOutSign="Y";//手动让当前验证码超时，让用户重新获取一次验证码
				/**********************************************计时器结束处理end**********************************************/
		 		
		 		
				//封装数据部分   正在处理。。。。。
		 		var encodedData = $("#encodedDataOnReply").val().trim();
		 		var encodedDataInsured = $("#encodedDataOnReplyInsured").val().trim();
				var holderSgData = $("#holderSgData").val().trim(); //投保人签名数据
				var insuredSgData = $("#insuredSgData").val()==undefined ? "":$("#insuredSgData").val().trim(); //被保人签名数据
				var retTyp = $("#retTyp").val().trim();//是否同意
				var retMsg = $("#retMsg").val().trim();//回复内容
				var chdrnum =  $("#chdrnumOnReply").val().trim();//保单号
				var apnum =  $("#apnumOnReply").val().trim();//申请单号
				var cownnum = $("#cownnumOnReply").val().trim();//投保人id
				var cownm = $("#cownmOnReply").val().trim();//投保人名称
				var lifenum = $("#lifenumOnReply").val().trim();//被保人id
				var lifenm = $("#lifenmOnReply").val().trim();//被保人名称
				var cntbranch = $("#cntbranchOnReply").val().trim();//保单机构号
				var chdrcoy = $("#chdrcoyOnReply").val().trim();//保单公司号
				var fromtyp = $("#fromtypOnReply").val().trim();//数据是从那个表获取的
				var pndate = $("#pndateOnReply").val().trim();//照会日期
				var imgData = [];//其他影像资料
				var otherPtDataCheck=$scope.otherPtData;
				for(var i=0;i<otherPtDataCheck.length;i++) {
					var ido = otherPtDataCheck[i].ido;
					var idPt_507="";
					if($("#idPt_"+ido).val()){
						idPt_507=$("#idPt_"+ido).val();
						imgData.push(idPt_507);
					}
				}
				//var zresnpdMap = groupMap;//照会列表，改由后台提取

		 		//传递参数，注意Tomcat要设一个max类型的值，因为数据量太大,否则报错
				var params={
					"encodedData" : encodedData,
					"encodedDataInsured" : encodedDataInsured,
					"holderSgData" : holderSgData,
					"insuredSgData" : insuredSgData,
					"retTyp" : retTyp,
					"retMsg" : retMsg,
					"chdrnum" :  chdrnum,
					"apnum" :  apnum,
					"cownnum" : cownnum,
					"cownm" : cownm,
					"lifenum" : lifenum,
					"lifenm" : lifenm,
					"cntbranch" : cntbranch,
					"chdrcoy" : chdrcoy,
					"fromtyp" : fromtyp,
					"pndate" : pndate
				};
				
				var timestamp=myFactory.getTimetamp();
				var sfis= "token-timestamp";
				var signStr="token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				//提交后台
//				//$timeout(function(){myFactory.loadingHide();},2000); 2秒这里并不足够，采用等待服务器响应比较好
				$http({
					method: 'post',
					url: app.domain + "pos/reply.action",
					data:{"paramsMap" : params , "paramsObj":imgData,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						if(response.data.code=="0"){
							myFactory.loadingHide();
							//$interval.cancel($scope.data.timeReply);//立即终止倒计时      变动：改为在提交前统一操作 By ZZQ 2017-11-10
							myFactory.alert('','回复成功！','info');
							$timeout(function(){ //2秒后跳转页面
								//跳转到查询界面
								$ionicHistory.clearCache().then(function(){ 
									$state.go('presentdeliver',{
										login:'yes'
									});
								});
							},2000);
						}else{
							myFactory.loadingHide();
							//$interval.cancel($scope.data.timeReply);//立即终止倒计时     变动：改为在提交前统一操作 By ZZQ 2017-11-10
							myFactory.alert('','数据出错，请返回重试！','info');
						}
					}else{
						myFactory.loadingHide();
						//$interval.cancel($scope.data.timeReply);//立即终止倒计时  变动：改为在提交前统一操作 By ZZQ 2017-11-10
						myFactory.alert('','系统没有响应，请返回重试','info');
					}
				}, function errorCallback(response) {
					myFactory.loadingHide();
					//$interval.cancel($scope.data.timeReply);//立即终止倒计时   变动：改为在提交前统一操作 By ZZQ 2017-11-10
					myFactory.alert('','访问后台失败，请返回重试！','info');
				});
			}
			//返回上一页
			$scope.goBack = function(){
				myFactory.goBack();
			}			
		}]);        
})(app)